package samba

import (
	"fmt"
	"net"

	"github.com/hirochachacha/go-smb2"
)

func Load(dicom string) []byte {
	conn, err := net.Dial("tcp", "192.168.100.4:445")
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("smb connection ok!")
	}
	defer func(conn net.Conn) {
		err := conn.Close()
		if err != nil {
			fmt.Printf("close connection error: %s", err)
		}
	}(conn)

	d := &smb2.Dialer{
		Initiator: &smb2.NTLMInitiator{
			User:     "antipov.ka",
			Password: "Ghjnjgkf3vf22",
			Domain:   "gsp.local",
		},
	}

	s, err := d.Dial(conn)
	if err != nil {
		fmt.Println(err)
	}
	defer func(s *smb2.Session) {
		err := s.Logoff()
		if err != nil {
			fmt.Printf("close connection error: %s", err)
		}
	}(s)

	fs, err := s.Mount("FONA$")
	if err != nil {
		fmt.Println(err)
	}
	defer func(fs *smb2.Share) {
		err := fs.Umount()
		if err != nil {

		}
	}(fs)

	var file []byte
	file, err = fs.ReadFile("Rent\\" + dicom)
	if err != nil {
		fmt.Println(err)
	}

	return file

}
